package de.tabuma.pm.projectnavigation.view;

import de.tabuma.pm.projectnavigation.logik.ProjectNavigationFacade;
import de.tabuma.pm.projectnavigation.entity.ProjectNavigation;
import de.tabuma.lib.tabumaview;
import de.tabuma.pm.*;
import de.tabuma.pm.logik.*;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author alefen
 */
public class view extends tabumaview {

    public view(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        if(request.getAttribute(constants.ProjectNavigationContent)!=null) {
            
            String id = (String) request.getAttribute(constants.ProjectNavigationContent);
            int idInt = Integer.valueOf(id).intValue();

            String navId = (String) request.getAttribute(constants.ProjectNavigationId);
            int navIdInt = Integer.valueOf(navId).intValue();
            
            String externalContent = this.getServlet() + "?" + this.getLinkAsAttribute() + "&amp;" + constants.ProjectNavigationId + "=" + request.getParameter(constants.ProjectNavigationId)+"&amp;"+constants.ProjectNavigationContent+"="+constants.ProjectNavigationExternalContent+"#"+constants.ProjectNavigationA;
            String htmlContent = this.getServlet() + "?" + this.getLinkAsAttribute() + "&amp;" + constants.ProjectNavigationId + "=" + request.getParameter(constants.ProjectNavigationId)+"&amp;"+constants.ProjectNavigationContent+"="+constants.ProjectNavigationHtmlContent+"#"+constants.ProjectNavigationA;

            String externalContentText = "external Content";
            String htmlContentText = "HTML Content";
            ProjectNavigation pn = ProjectNavigationFacade.get(navIdInt);
            String contentPn = "Content "+pn.getName();


            out.println("<div class=\"navebene_label\">"+contentPn+"</div>");

            switch(idInt) {
                case constants.ProjectNavigationExternalContent:
                    out.println("<div class=\"navline\">");
                    out.println("<div class=\"tabelementbeginnclose\"></div>");
                    out.println("<div class=\"tabelementopen\">"+externalContentText+"</div>");
                    out.println("<div class=\"tabelementclose\"><a href=\""+htmlContent+"\">"+htmlContentText+"</a></div>");
                    out.println("<div class=\"tabelementclose\"></div>");
                    out.println("</div>");
                    out.println("<div class=\"contentContent\">");
                    Hashtable param1 = (Hashtable) this.getParameter().clone();
                    param1.put(constants.ProjectNavigationContent,""+constants.ProjectNavigationExternalContent);
                    param1.put(constants.ProjectNavigationId, navId);
                    de.tabuma.pm.externalcontent.view.view ecv = new de.tabuma.pm.externalcontent.view.view(this.getServlet(), param1);
                    ecv.processRequest(context, request, response, out);
                    out.println("</div>");
                    break;
                default:
                    out.println("<div class=\"navline\">");
                    out.println("<div class=\"tabelementbeginnclose\"></div>");
                    out.println("<div class=\"tabelementclose\"><a href=\""+externalContent+"\">"+externalContentText+"</a></div>");
                    out.println("<div class=\"tabelementopen\">"+htmlContentText+"</div>");
                    out.println("<div class=\"tabelementclose\"></div>");
                    out.println("</div>");
                    out.println("<div class=\"contentContent\">");
                    Hashtable param2 = (Hashtable) this.getParameter().clone();
                    param2.put(constants.ProjectNavigationContent,""+constants.ProjectNavigationHtmlContent);
                    param2.put(constants.ProjectNavigationId, navId);
                    de.tabuma.pm.htmlcontent.view.view hcv = new de.tabuma.pm.htmlcontent.view.view(this.getServlet(), param2);
                    hcv.processRequest(context, request, response, out);
                    out.println("</div>");
                    break;
            }
        }

    }

}